Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

level-sublevel

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-sublevel

partition levelup databases

  • 6.6.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is level-sublevel?

The level-sublevel package is a plugin for LevelDB that allows you to create sublevel sections within a LevelDB database. This can help in organizing and managing data more effectively by creating isolated namespaces within the same database.

What are level-sublevel's main functionalities?

Creating Sublevels

This feature allows you to create sublevels within your LevelDB database. In the example, two sublevels 'users' and 'posts' are created, and data is added to each sublevel.

const level = require('level');
const sublevel = require('level-sublevel');

const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');
const posts = sub.sublevel('posts');

users.put('user1', { name: 'Alice' }, function (err) {
  if (err) return console.log('Ooops!', err);
  console.log('User added!');
});

posts.put('post1', { title: 'Hello World' }, function (err) {
  if (err) return console.log('Ooops!', err);
  console.log('Post added!');
});

Batch Operations

This feature allows you to perform batch operations on a sublevel. In the example, multiple user records are added in a single batch operation.

const level = require('level');
const sublevel = require('level-sublevel');

const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');

users.batch()
  .put('user2', { name: 'Bob' })
  .put('user3', { name: 'Charlie' })
  .write(function (err) {
    if (err) return console.log('Ooops!', err);
    console.log('Batch operation complete!');
  });

Stream Operations

This feature allows you to create a read stream to iterate over all entries in a sublevel. In the example, all user records are read and printed to the console.

const level = require('level');
const sublevel = require('level-sublevel');

const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');

users.createReadStream()
  .on('data', function (data) {
    console.log(data.key, '=', data.value);
  })
  .on('error', function (err) {
    console.log('Error:', err);
  })
  .on('end', function () {
    console.log('Stream ended');
  });

Other packages similar to level-sublevel

FAQs

Package last updated on 09 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc